package example.kristin.mybatis;

import example.kristin.mybatis.entity.MyEntity;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;

public class MybatisTest {

    public static void main(String[] args) throws IOException {
        MyEntity myEntity = new MyEntity();
        myEntity.setName("kristin1");
        InputStream is = Resources.getResourceAsStream("mybatis-config.xml");
        SqlSessionFactoryBuilder builder =  new SqlSessionFactoryBuilder();
        SqlSessionFactory factory = builder.build(is);
        SqlSession sqlSession = factory.openSession();
        int nums = sqlSession.insert("example.mybatis.saveMyEntity", myEntity);
        System.out.println("影响的行数 -- " + nums);
        sqlSession.commit();
        sqlSession.close();
    }

}
